package cn.wolfcode.ssm.service.impl;

import cn.wolfcode.ssm.domain.OperationLog;
import cn.wolfcode.ssm.mapper.OperationLogMapper;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.IOperationLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperationLogServiceImpl implements IOperationLogService {

    @Autowired
    private OperationLogMapper operationLogMapper;


    @Override
    public void save(OperationLog operationLog) {
        operationLogMapper.insert(operationLog);
    }

    @Override
    public void delete(Long id) {
        operationLogMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(OperationLog operationLog) {
        operationLogMapper.updateByPrimaryKey(operationLog);
    }

    @Override
    public OperationLog get(Long id) {
        return operationLogMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<OperationLog> listAll() {
        return operationLogMapper.selectAll();
    }

    @Override
    public PageInfo<OperationLog> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<OperationLog> operationLogs = operationLogMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<OperationLog>(operationLogs);
    }
}
